home *** CD-ROM | disk | FTP | other *** search
- #include <PPCToolbox.h>
- #include <EPPC.h>
- #include <Errors.h>
- #include <TextUtils.h>
- #include <Dialogs.h>
- #include <Strings.h>
-
- #ifndef __GESTALTEQU__
- #include <GestaltEqu.h>
- #endif
-
- #ifndef __APPLEEVENTS__
- #include <AppleEvents.h>
- #endif
-
- #include "Symbiont.h"
- #include "Javelin.h"
- #include "JavelinEvents.h"
- #include "version.h"
-
- // External Function Prototypes
- Boolean IsAppWindow(WindowPtr window);
- void New_Window(void);
- void snd_null(void);
- extern pascal Boolean snd_version(void);
- extern pascal OSErr HandleHeartBeat(AppleEvent *msg,AppleEvent *reply,long refcon);
- extern pascal OSErr HandleQuit(AppleEvent *msg,AppleEvent *reply,long refcon);
- void AlertUser( short error );
-
-
-
- // Local symbiont function prototypes
- void new_connection(void);
- void Javelin_AlertUser( short error );
- static pascal Boolean MyPPCBrowserFilter(LocationNamePtr, PortInfoPtr thePortInfo);
- void InstallAppleEventHandlers(void);
- static pascal OSErr HandleMsg(AppleEvent *msg,AppleEvent *reply,long refcon);
- void snd_interval(int interval);
-
-
- /* Global Variables */
- Str255 hostname;
- PPCSessRefNum TheSessionID;
- short ThePortRefNum;
- long sessionID=0;
-
- // External globals
- extern TargetID TheTarget;
-
- /* A DocumentRecord contains the WindowRecord for one of our document windows,
- as well as the TEHandle for the text we are editing. Other document fields
- can be added to this record as needed. For a similar example, see how the
- Window Manager and Dialog Manager add fields after the GrafPort. */
- typedef struct {
- WindowRecord docWindow;
- Str255 docTEXT[255];
- ControlHandle docVScroll;
- ControlHandle docHScroll;
- ProcPtr docClik;
- } DocumentRecord, *DocumentPeek;
-
-
- #pragma segment main
-
- void new_connection(void)
- {
- PortInfoRec thePortInfo;
- OSErr err;
- int TheInterval=10;
-
- err = PPCInit();
- err = PPCBrowser("\pSelect a Javelin Server...",
- "\pServers",
- FALSE,
- &(TheTarget.location),
- &thePortInfo,
- MyPPCBrowserFilter,
- "\pUNIX PPCToolbox");
-
- if (err == userCanceledErr) return;
-
- if (err) {
- AlertUser(ePPCError);
- return;
- }
-
- // to allow connection to the local host simply comment out this if statement
- if (TheTarget.location.locationKindSelector == 0) {
- AlertUser(eOurMachine);
- BlockMove("Local Connection",hostname,17);
- return;
- }
-
- TheTarget.name = thePortInfo.name;
-
- if (TheTarget.location.locationKindSelector == 0)
- BlockMove("\pLocal Connection",&hostname,18);
- else
- BlockMove(TheTarget.location.u.nbpEntity.objStr,&hostname,sizeof(hostname));
-
- (void)snd_null();
-
- if (snd_version() == FALSE) return;
-
- (void)snd_interval(TheInterval);
-
- (void)New_Window();
-
- }
-
- #pragma segment main
- //MW Changed prototype style to new C (old C to new C)
- void Javelin_AlertUser(short error)
- {
- short itemHit;
- Str255 message;
-
- SetCursor(&qd.arrow);
- GetIndString(message, kJavelinStrings, error);
- ParamText(message, "\p", "\p", "\p");
- itemHit = Alert(rUserAlert, nil);
- } /* Javelin_AlertUser */
-
-
- static pascal Boolean MyPPCBrowserFilter(LocationNamePtr /* theLocation */, PortInfoPtr thePortInfo)
- {
- OSType type;
-
- if (thePortInfo->name.portKindSelector == ppcByString)
- {
- // The BlockMove is so that we don't get an address error on a
- // 68000-based machine due to referencing a long at an odd-address.
- BlockMove(thePortInfo->name.u.portTypeStr + 1, &type, sizeof(type));
- if (type == kSignature)
- return TRUE;
- }
- return FALSE;
- }
-
- typedef struct _AEHandler {
- AEEventID theAEEventID;
- AEEventHandlerProcPtr handler;
- } AEHandler;
-
-
- AEHandler handlerTable[] = {
- {kAEHeartBeat, (AEEventHandlerProcPtr)HandleHeartBeat},
- {kAEJavMsg, (AEEventHandlerProcPtr)HandleMsg},
- {kAEQuit, (AEEventHandlerProcPtr)HandleQuit}
- };
-
-
- void InstallAppleEventHandlers(void)
- {
- int i;
-
- for (i = 0; i < sizeof(handlerTable) / sizeof(AEHandler); i++)
- {
- AEInstallEventHandler(kAEAUXSuite, handlerTable[i].theAEEventID, (AEEventHandlerProcPtr)handlerTable[i].handler, 0L, false);
- }
-
- }
-
-
- pascal OSErr HandleMsg(AppleEvent *msg,AppleEvent *reply,long refcon)
- {
- DescType returnedType;
- Size returnedSize;
- int msgcode;
- char tmpdata[1024];
- int retval;
- WindowPtr window;
- Rect r;
-
- retval=AEGetParamPtr (msg, keyMessageCode, typeInteger, &returnedType,&msgcode, sizeof(msgcode), &returnedSize);
- retval=AEGetParamPtr (msg, keyMsgString, typeChar, &returnedType,tmpdata, 1024, &returnedSize);
- tmpdata[returnedSize-1] = '\0';
-
- window = FrontWindow();
- if ( IsAppWindow(window) ) {
- r=window->portRect;
- SetRect(&r,0,5,450,28);
- TextBox((Ptr)tmpdata, returnedSize, &r, teJustCenter);
- }
-
- return(noErr);
-
- }
-
-
-
- void snd_interval(int interval)
- {
- char status;
- char ErrorString[64];
- AppleEvent theAppleEvent;
- AppleEvent reply;
- AESendMode sendMode;
- AESendPriority sendPriority;
- AEAddressDesc target;
- DescType returnedType;
- Size returnedSize;
- long timeOutInTicks;
- int retval, result;
- long ival;
-
- ival=(long)interval;
-
- retval=AECreateDesc(typeTargetID,&TheTarget,sizeof(TargetID),&target);
- retval=AECreateAppleEvent(kAEAUXSuite,kAEInterval,&target, kAutoGenerateReturnID,kAnyTransactionID,&theAppleEvent);
- retval=AEPutParamPtr(&theAppleEvent,keySessionID,typeLongInteger,&TheTarget.sessionID,sizeof(TheTarget.sessionID));
- retval=AEPutParamPtr(&theAppleEvent,keyInterval,typeLongInteger,&ival,sizeof(ival));
- sendMode = kAEWaitReply;
- sendPriority = kAENormalPriority;
- timeOutInTicks = kAEDefaultTimeout;
- retval=AESend(&theAppleEvent,&reply,sendMode,sendPriority,timeOutInTicks,NULL,NULL);
- AEDisposeDesc(&target);
- AEDisposeDesc(&theAppleEvent);
- if (retval == noErr) {
- result = AEGetParamPtr(&reply,keyErrorNumber,typeChar,&returnedType,(Ptr)&status,sizeof(char),&returnedSize);
- result = AEGetParamPtr(&reply,keyErrorString,typeChar,&returnedType,(Ptr)ErrorString,64,&returnedSize);
- ErrorString[returnedSize]='\0';
- if (status == 'F') {
- Javelin_AlertUser(eInterval);
- }
- }
- else
- AlertUser(eAESend);
- }
-